package com.louis.iread.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.louis.iread.R;
import com.louis.iread.bean.ClassItem;
import com.louis.iread.skin.SkinMgr;

import java.util.List;

/**
 * Created by louis on 18-5-5.
 */

public class ClassifyAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater inflater;
    private int layoutId;
    List<ClassItem> list;

    public ClassifyAdapter(Context context, int layoutId, List<ClassItem> list) {
        this.context = context;
        this.layoutId = layoutId;
        this.list = list;
        this.inflater = LayoutInflater.from(this.context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = inflater.inflate(layoutId, parent, false);
        }

        TextView textView = (TextView)convertView.findViewById(R.id.text_item);
        ClassItem item = (ClassItem) getItem(position);
        textView.setText(item.getTitle());

        SkinMgr.getInstance().applyView(convertView);

        return convertView;
    }
}
